package cn.wolfcode.web.controller;

import cn.wolfcode.enums.BusinessReportEnum;
import cn.wolfcode.qo.BusinessReportQueryObject;
import cn.wolfcode.service.IBusinessReportService;
import cn.wolfcode.service.IBusinessService;
import cn.wolfcode.service.IConsumptionItemService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/customerReport")
public class BusinessReportController {
    @Autowired
    private IBusinessReportService businessReportService;
    @Autowired
    private IBusinessService businessService;
    @Autowired
    private IConsumptionItemService consumptionItemService;
    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") BusinessReportQueryObject qo){
        PageInfo pageInfo = businessReportService.queryGroupByName(qo);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("business",businessService.listAll());
        model.addAttribute("groupByItem", BusinessReportEnum.values());
        return "businessReport/list";
    }

    @RequestMapping("/delete")
    public String list(Long[] ids,Long consumptionId){
        for (Long i:ids){
            consumptionItemService.delete(i);
        }
        return "redirect:/consumption/input?id="+consumptionId;
    }
}
